package com.smart.service;

import java.sql.SQLException;
import java.util.List;

import com.smart.dao.AdminDAO;
import com.smart.model.Admin;

public class AdminService {
	 public  static AdminDAO adminDAO=null;
	 static
	 {
		 adminDAO=new AdminDAO();
	 }
	 public Admin loginCheck(String telephoneNum,String password)
	 {
		 Admin admin=null;
		 try {
			admin=adminDAO.loginCheck(telephoneNum, password);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		 return admin;
	 }
	 
	 //pageIndex为第几页，pageSize为每页多少条记录
	   public List<Admin> getAdminList(int pageIndex,int pageSize,int communityId)
	   {
		   List<Admin> adminList=null;
		   try {
			adminList=adminDAO.getAdminList(pageIndex, pageSize,communityId);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		   return adminList;
	   }
	   
	 //获取总数
	   public int getCount(int communityId)
	   {
		   int count=-1;
		   try {
			count=adminDAO.getCount(communityId);
		   } catch (SQLException e) {
			e.printStackTrace();
		   }
		   return count;
	   }
	   
	   //添加管理员
	   public int addAdmin(String password,int type,String telephoneNum,String adminName,int communityId)
	   {
		   int x=0;
		   try 
		   {
			  x=adminDAO.addAdmin(password, type, telephoneNum, adminName,communityId);
		   } 
		   catch (SQLException e) 
		   {
			e.printStackTrace();
		   }
		   return x;
	   }
	   
	   //删除管理员
	   public int deleteAdmin(int id)
	   {
		   int x=0;
		   try {
			x=adminDAO.deleteAdmin(id);
		 } catch (SQLException e) {
			e.printStackTrace();
		 }
		   return x;
	   }
	   
	 //更新管理员信息
	   public int updateAdmin(Admin admin)
	   {
		   int x=0;
		   try {
			x=adminDAO.updateAdmin(admin);
		 } catch (SQLException e) {
			e.printStackTrace();
		 }
		   return x;
	   }
	   
	   //根据电话号码进行搜索
	   public List<Admin> searchAdminByTele(String telephoneNum,int communityId)
	   {
		   List<Admin> adminList=null;
		   try {
			adminList=adminDAO.searchAdminByTele(telephoneNum,communityId);
		   } catch (SQLException e) {
			e.printStackTrace();
		   }
		   return adminList;
	   }
	   
	   //根据管理员姓名进行搜索
		public List<Admin> searchAdminByAdminName(String adminName,int communityId)
		{
			  List<Admin> adminList=null;
			   try {
				adminList=adminDAO.searchAdminByAdminName(adminName,communityId);
			   } catch (SQLException e) {
				e.printStackTrace();
			   }
			   return adminList;
		}
}
